<?php
   // include function files for this application
   require_once('/home/domains/uny-con.com/public_html/uny-con_fns.php');
   if (!session_id()) { session_start(); }


   if (!check_valid_user()) {
      // they are not logged in 
      do_html_header('You must be logged in', staysmall, $uny);
      echo 'You are not logged in.<br />';
      do_html_url('login.php', 'Login');
      print_brs(6);
      do_html_footer(news);
      exit;
   }/*
//We don't want people accessing this page during the con.

if (!check_valid_user() || ($_SESSION['admin'] != 't')) {
	do_html_header('Unauthorized access', staysmall, $uny);
	echo 'We are sorry, Event sign-up is not yet available. Registration for events will be available on September 20th.';
	print_brs(24);
	do_html_footer(news);
	exit;
	}
*/
$registration_status = get_con_attendance_status($_SESSION['current_attendee_id']);
if ($registration_status != 'approved' && $registration_status != 'pending') {
	// their reg status does not appear to be approved. 
	do_html_header('Registration', staysmall, $uny);
	echo 'It appears that you are not yet registered for the con. Please <a href="http://loki.local/~plummer/uny-con/registration/register_for_con.php">register</a> and then try signing up for events again. If you think are seeing this page in error please <a href="webmaster@uny-con.com">email</a> us.<br />';
	print_brs(6);
	do_html_footer(news);
	exit;
}

// get the variables we need.
$action = $_GET['action'];
$event_id = $_GET['event_id'];
$start_time = $_GET['start_time'];
$attendee_id = $_SESSION['current_attendee_id'];

// now figure out what days they can register for.
$event_day = get_con_attendance_day($_SESSION['current_attendee_id']);
$attendance_type = get_con_attendance_type($_SESSION['current_attendee_id']);

// Timeslots for dates
// 1 - 2 - 3 Friday
// 4 - 5 - 6 - 7 - 8 Saturday
// 9 - 10 - 11 Sunday
// All Week-end is really all

// If they have a gm only badge they are not allowed to sign up to play anything.
if ($attendance_type == 'gm only' && $action == 'add') {
	do_html_header('Registration', staysmall, $uny);
	echo 'It appears that you have a GM Only badge, this badge type does not allow participation in any events. Please <a href="http://loki.local/~plummer/uny-con/index.php?uny=contact_form.php">contact us</a> to have your badge type changed if you would like to participate in events.<br />';
	print_brs(6);
	do_html_footer(news);
	exit;
	}

// If they have a LARP only badge make sure they can only register for the LARP.
if ($attendance_type == 'LARP only' && $action == 'add' && $event_id != '9445') {
	do_html_header('Registration', staysmall, $uny);
	echo 'Your current badge type "'.$attendance_type.'" does not permit you signing up for this event. You need to <a href="http://loki.local/~plummer/uny-con/index.php?uny=contact_form.php">contact us</a> to have your badge upgraded.  The only event you are allowed tos ign up for is the LARP "<a href="http://loki.local/~plummer/uny-con/registration/eventdetails.php?searchtype=eventid&searchterm=9445">Under Pressure</a>".<br />';
	print_brs(6);
	do_html_footer(news);
	exit;
	}
/* -- Commenting out code that checks con days.  Needs to be updated with new con functionality
if ($event_day == 'friday' && ($starting_timeslot < '0' || $starting_timeslot > '3') && $action == 'add') {
	do_html_header('Registration', staysmall, $uny);
	echo 'You are only registered for a '.ucwords($event_day).' pass. If you would like to change this or think this is an error please <a href="http://loki.local/~plummer/uny-con/index.php?uny=contact_form.php">contact us</a>.<br />';
	print_brs(6);
	do_html_footer(news);
	exit;
	} 
if ($event_day == 'saturday' && (($starting_timeslot < '4' || $starting_timeslot > '8') && $starting_timeslot != '0') && $action == 'add') {
	do_html_header('Registration', staysmall, $uny);
	echo 'You are only registered for a '.ucwords($event_day).' pass. If you would like to change this or think this is an error please <a href="http://loki.local/~plummer/uny-con/index.php?uny=contact_form.php">contact us</a>.<br />';
	print_brs(6);
	do_html_footer(news);
	exit;
	}
if ($event_day == 'sunday' && (($starting_timeslot < '9' || $starting_timeslot > '11') && $starting_timeslot != '0') && $action == 'add') {
	do_html_header('Registration', staysmall, $uny);
	echo 'You are only registered for a '.ucwords($event_day).' pass. If you would like to change this or think this is an error please <a href="http://loki.local/~plummer/uny-con/index.php?uny=contact_form.php">contact us</a>.<br />';
	print_brs(6);
	do_html_footer(news);
	exit;
	}
*/


if ($action == 'delete') {
	$cost = get_event_cost($eventid);
	if ($cost != 0.00) eventdel_confirmation_email($attendee_id, $event_id, $start_time);
	$delsql = delete_event_reg($event_id, $start_time, $attendee_id);
			
	if ($delsql == true) {
		header("Location: ".$conf['base_path']."registration/attendee_home.php");
		exit;
		}
	} 
if ($action == 'add') {
	$addsql = add_event_reg($event_id, $start_time, $attendee_id);
	if ($addsql == 'full') {
		do_html_header('Event full!', staysmall, $uny);
		echo 'The event you tried to sign up for was full please select another event.';
		print_event_search_form();
		print_brs(6);
		do_html_footer(news);
		exit;
		}
	if ($addsql != 'false' && $_SESSION['admin'] == 't') {
		header("Location: ".$conf['base_path']."registration/attendee_home.php");
		exit;
		}
	do_html_header('Event registration succeeded', staysmall, $uny);
	if ($addsql == pending) {
		echo '<p>Your registration for this event has been marked pending. Please select all the other events you would like to play in and then use the checkout button on schedule page.</p><br />';
		}
	if ($addsql != 'false') {
		echo "<p>You have been added to event $event_id.</p><br />";
		echo 'Search for another event:<br />';
		print_event_search_form();
	echo "<p><a href=\"event_list.php\"><img src=\"images/continue-registering.gif\" alt=\"Continue registering for events\" width=\"140\" height=\"40\" border=\"0\"></a> <a href=\"attendee_home.php\"><img src=\"images/view-schedule.gif\" alt=\"View your schedule\" width=\"140\" height=\"40\" border=\"0\"></a></p>";
		}
	}
do_html_footer(news);

?>